package com.wutong.common_server.result;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
public class CommonResultPage implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -8573855566812280377L;

	/**
	 * 0为返回正常， 其它code均为请求错误
	 */
	private String code;

	/**
	 * 返回数据
	 */
	private Object data;

	/**
	 * 错误信息
	 */
	private String msg;

	private Long timestamp;



	public CommonResultPage() {
		this.code = "0000";
		this.msg = "";
	}

	public CommonResultPage(Object data) {
		this();
		this.data = data;
	}

	public CommonResultPage(String msg) {
		this.code = "9999";
		this.msg = msg;
	}

	public CommonResultPage(String code, String msg) {
		this.code = code;
		this.msg = msg;
	}


	public CommonResultPage(String code, String msg , Object data , DataTablePageDto<Object> tablePage) {
		long total = ((Page<Object>) data).getTotal();
		tablePage.setTotal(total);
		tablePage.setRows(((Page<Object>) data).getRecords());
		this.code = code;
		this.msg = msg;
		this.data = tablePage;
		this.timestamp = new Date().getTime();
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return this.code + ";" + this.msg;
	}


}
